import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/api/api_response.dart';
import 'package:flutter_changdian_football/api/req/other/req_other.dart';
import 'package:flutter_changdian_football/model/other/user_notify_setting_model.dart';
import 'package:get/get.dart';

class PushSettingController extends GetxController {

  @override
  void onInit() {
    super.onInit();
    initData();
  }

  UserNotifySettingModel? userNotifySettingModel;

  initData() async {
    var resp = await ReqOther.getUserNotifySetting();
    if (resp.status == Status.completed) {
      if (resp.data['code'] == '200') {
        userNotifySettingModel = UserNotifySettingModel.fromJson(resp.data['data']);
        update();
      }
    }
  }

  userNotifySet(int p) async {
    if (p == 0) {
      if (userNotifySettingModel?.allSwitch == 'ON') {
        userNotifySettingModel?.allSwitch = 'OFF';
      } else {
        userNotifySettingModel?.allSwitch = 'ON';
      }
    }


    if (p == 1) {
      if (userNotifySettingModel?.matchNotify == 'ON') {
        userNotifySettingModel?.matchNotify = 'OFF';
      } else {
        userNotifySettingModel?.matchNotify = 'ON';
      }
    }

    if (p == 2) {
      if (userNotifySettingModel?.clubDynamicNotify == 'ON') {
        userNotifySettingModel?.clubDynamicNotify = 'OFF';
      } else {
        userNotifySettingModel?.clubDynamicNotify = 'ON';
      }
    }


    if (p == 3) {
      if (userNotifySettingModel?.praiseNotify == 'ON') {
        userNotifySettingModel?.praiseNotify = 'OFF';
      } else {
        userNotifySettingModel?.praiseNotify = 'ON';
      }
    }


    if (p == 4) {
      if (userNotifySettingModel?.interestNotify == 'ON') {
        userNotifySettingModel?.interestNotify = 'OFF';
      } else {
        userNotifySettingModel?.interestNotify = 'ON';
      }
    }


    if (p == 5) {
      if (userNotifySettingModel?.systemNotify == 'ON') {
        userNotifySettingModel?.systemNotify = 'OFF';
      } else {
        userNotifySettingModel?.systemNotify = 'ON';
      }
    }



    if (p == 6) {
      if (userNotifySettingModel?.clubCheckNotify == 'ON') {
        userNotifySettingModel?.clubCheckNotify = 'OFF';
      } else {
        userNotifySettingModel?.clubCheckNotify = 'ON';
      }
    }
    update();

    var resp = await ReqOther.userNotifySet(
      allSwitch: userNotifySettingModel?.allSwitch,
      clubCheckNotify: userNotifySettingModel?.clubCheckNotify,
      clubDynamicNotify: userNotifySettingModel?.clubDynamicNotify,
      interestNotify: userNotifySettingModel?.interestNotify,
      matchNotify: userNotifySettingModel?.matchNotify,
      praiseNotify: userNotifySettingModel?.praiseNotify,
      systemNotify: userNotifySettingModel?.systemNotify,
    );
    if (resp.status == Status.completed) {
      if (resp.data['code'] == '200') {
        update();
      }
    }
  }

}